package com.rinlink.jbcodec.transform;


public class StringArrayToBytes implements Transform<byte[]> {

    String[] strings;
    int elementLength;
    int arraySize;

    public StringArrayToBytes(String[] strings, int elementLength, int arraySize) {
        this.strings = strings;
        this.elementLength = elementLength;
        this.arraySize = arraySize;
    }

    @Override
    public byte[] transform() {
        byte[] array = new byte[elementLength * arraySize];
        for (int i = 0; i < strings.length; i++){
            byte[] strBytes = strings[i].getBytes();

            int strLen = strBytes.length;
            for (int j = 0; j < strLen; j++){
                array[i * elementLength + j] = strBytes[j];
            }
        }
        return array;
    }
}
